from chernc.treediff.gumtree.actions.model.action import Action
from chernc.treediff.gumtree.tree.tree import TreeLike


class Update(Action):
    def __init__(self, node: TreeLike, value: str):
        super().__init__(node)
        self.value = value

    def get_name(self) -> str:
        return "update-node"

    def get_value(self) -> str:
        return self.value

    def __str__(self) -> str:
        return f"===\n{self.get_name()}\n---\n{self.node}\nreplace {self.node.get_label()} by {self.get_value()}"

    def __eq__(self, other: object) -> bool:
        if not isinstance(other, Update):
            return False
        if not super().__eq__(other):
            return False
        return self.value == other.value
